<template>
  <div>
    <a-modal
      title="修改密码"
      :visible="showPSWDdDlg"
      @ok="passwordOk"
      @cancel="showPSWDdDlg=false"
    >
      <a-input-password placeholder="原密码" />
      <a-input-password placeholder="新密码" />
      <a-input-password placeholder="重复输入新密码" />
    </a-modal>
    <a-dropdown>
      <div class="header-avatar" style="cursor: pointer">
        <a-avatar
          class="avatar"workd
          size="small"
          shape="circle"
          :src="user.avatar"
        />
        <span class="name">{{ user.name }}</span>
      </div>
      <a-menu :class="['avatar-menu']" slot="overlay">
        <a-menu-item>
          <a-icon type="user" />
          <span>修改密码</span>
        </a-menu-item>
        <a-menu-item>
          <a-icon type="setting" />
          <span>修改设置</span>
        </a-menu-item>
        <a-menu-divider />
        <a-menu-item @click="logout">
          <a-icon style="margin-right: 8px" type="poweroff" />
          <span>退出登录</span>
        </a-menu-item>
      </a-menu>
    </a-dropdown>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import { logout } from "@/services/user";

export default {
  name: "HeaderAvatar",
  computed: {
    ...mapGetters("account", ["user"]),
  },
  data(){
    return {
      showPSWDdDlg:false,
      oldPswd:'',
      newPswd:'',
      reNewPswd:'',
    }
  },
  methods: {
    logout() {
      logout();
      this.$router.push("/login");
    },
    passwordOk(){
      this.showPSWDdDlg = false
    }
  },
};
</script>

<style lang="less">
.header-avatar {
  display: inline-flex;
  .avatar,
  .name {
    align-self: center;
  }
  .avatar {
    margin-right: 8px;
  }
  .name {
    font-weight: 500;
  }
}
.avatar-menu {
  width: 150px;
}
</style>
